<template>
  <div>
    <el-row>
      <el-col :span="3">
        <el-input v-model="color" placeholder="请输入员工名称"></el-input>
      </el-col>
      <el-col :span="20">
        <el-button @click="clolr_click" class="add_btn" icon="el-icon-search">
          搜索</el-button>
          <el-button @click="clolr_clicks"
          icon="el-icon-refresh"
          class="add_btn">
          重置</el-button>
        <el-button @click="search(2)" class="add_btn" icon="el-icon-search">
          导出</el-button
        >
      </el-col>
    </el-row>
    <el-table :data="dataList" stripe style="width: 100%" border>
      <el-table-column prop="color" label="员工姓名">
        <template slot-scope="scope">
          <span v-if="scope.row.employee">
            {{ scope.row.employee.employee_name }}
          </span>
         
        </template>
      </el-table-column>
      <el-table-column prop="order_count" label="工单完成数"> </el-table-column>
      <el-table-column prop="base_pay" label="员工工资">
        <template slot-scope="scope">
          <span v-if="scope.row.employee">
            {{ scope.row.employee.base_pay }}
          </span>
        </template>
      </el-table-column>
      <el-table-column prop="total_sales" label="工单总金额"> </el-table-column>
      <el-table-column prop="created_at" label="合计">
        <template slot-scope="scope">
          <span v-if="scope.row.employee&& scope.row.total_sales">
          {{
            Number(scope.row.employee.base_pay) + Number(scope.row.total_sales)
          }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="200">
        <template slot-scope="scope">
            <!-- <router-link :to="'/getSalaryList/yggongzilist'+scope.row.id">
              <el-button type="primary" size="small" icon="el-icon-edit">Edit</el-button>
            </router-link> -->
           
          <el-button
            @click="set_product(scope.row.employee.user_id)"
            type="text"
            icon="el-icon-edit"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        background
        @prev-click="prev"
        @next-click="next"
        :current-page.sync="pagination.page"
        :page-size="pagination.per_page"
        layout="total, prev, pager, next"
        :total="total"
      >
      </el-pagination>
    </div>

    <el-dialog
      title="调货信息"
      :visible.sync="isjilu"
      width="40%"
      @close="close_dialog"
    >
    <div>
         <!-- <el-row>
        <el-col :span="3"> 
          <el-input v-model="color" placeholder="请输入员工名称"></el-input>
        </el-col>
        <el-col :span="4">
          <el-button @click="clolr_click"  class="add_btn"  icon="el-icon-search"> 搜索</el-button>
        </el-col>
      </el-row> -->
      <el-table :data="dataList" stripe style="width: 100%" border>
        <el-table-column label="客户">
            <template slot-scope="scope">
                {{scope.row.order.customer.customer_name}}
            </template>
        </el-table-column>
        <el-table-column prop="order_count" label="产品"> 
          <template slot-scope="scope">
                {{scope.row.order.product.product_name}}
            </template>
        </el-table-column>
        <el-table-column label="颜色"> 
            <template slot-scope="scope">
                {{scope.row.order.color.color}}
            </template>
        </el-table-column>
        <el-table-column label="型号"> 
          <template slot-scope="scope">
                {{scope.row.order.model_number.model_number}}
            </template>
        </el-table-column>
        <el-table-column label="规格">
          <template slot-scope="scope">
                {{scope.row.order.specification.specification}}
            </template>
        </el-table-column>
        <el-table-column  label="金额"> 
            <template slot-scope="scope">
                {{scope.row.price}}
            </template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template slot-scope="scope">
            <el-button
              @click="set_product(scope.row)"
              type="text"
              icon="el-icon-edit"
              >修改</el-button
            >
          </template>
        </el-table-column>
      </el-table>
  
      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          @prev-click="prev"
          @next-click="next"
          :current-page.sync="pagination.page"
          :page-size="pagination.per_page"
          layout="total, prev, pager, next"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
     <span slot="footer" class="dialog-footer">
        <el-button @click="isjilu = false">取 消</el-button>
      </span>
    </el-dialog>

    <el-dialog
        :title="title"
        :visible.sync="isProduct"
        width="30%"
        :close-on-click-modal="false"
        @close="close_dialog"
      >
        <el-form
          :model="ruleForm"
          :rules="rules"
          ref="ruleForm"
          label-width="100px"
          class="demo-ruleForm"
        >
          <el-form-item label="金额" prop="color">
            <el-input v-model="ruleForm.price"  placeholder="请输入金额"></el-input>    
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="isProduct = false">取 消</el-button>
          <el-button type="primary" @click="submitadd('ruleForm')"
            >确定</el-button
          >
        </span>
      </el-dialog>

    

    
  </div>
</template>
<script>
import { getSalaryList, createColor, delColor ,getSalaryInfo,changeSalary} from "@/api/product/index";
export default {
  data() {
    return {
      color: "",
      title: "",
      isProduct: false,
      dataList: [],
      ruleForm: {
        color: "",
        id: "",
      },
      rules: {
        color: [
          {
            required: true,
            message: "请输入颜色或以英文, 号隔开",
            trigger: "blur",
          },
        ],
      },
      pagination: {
        per_page: 10,
        page: 1,
      },
      total: 0,
    };
  },
  mounted() {
    this.getlist();
  },
  methods: {
    search(type) {
        getSalaryList(this.ser).then((res) => {
        if (res.code == 200) {
          this.dataList = res.data.data;
          this.total = res.data.total;
          if (type == 2) {
            if (res.data.data.length > 0) {
              this.$message.success("正在导出订单列表");
              this.exports_w();
            }
          }
        }
      });
    },
    exports_w(){
        let data = {
        ...this.ser,
        export: 1,
      };
      getSalaryList(data).then((res) => {
        //创建一个隐藏的a连接，
        const link = document.createElement("a");
        let blob = new Blob([res.data], { type: "application/vnd.ms-excel" });
        link.style.display = "none";
        //设置连接
        link.href = URL.createObjectURL(blob);
        link.download = "员工工资列表";
        document.body.appendChild(link);
        //模拟点击事件
        link.click();
      });
    },
    close_dialog() {
      this.ruleForm = {
        color: "",
        id: "",
      };
    },
    del_product(row) {
      console.log("ww");
      delColor({
        id: row.id,
        is_del: 1,
      }).then((res) => {
        if (res.code == 200) {
          this.isProduct = false;
          this.$message.success("提交成功");
          this.getlist();
        }
      });
    },
    getlist() {
      getSalaryList({...this.color,...this.pagination}).then((res) => {
        if (res.code == 200) {
          this.dataList = res.data.data;
          this.total = res.data.total;
        }
      });
    },
    set_product(id) {
      console.log(id);
      this.$router.push({
        // name: "yggongzilist",
        path: "/getSalaryList/yggongzilist",
        query: {
          id,
        },
      });
    },
    add_color() {
      this.title = "新增颜色";
      this.isProduct = true;
      this.$nextTick(function () {
        this.$refs.ruleForm.resetFields();
      });
    },
    submitadd(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          createColor(this.ruleForm).then((res) => {
            if (res.code == 200) {
              this.isProduct = false;
              this.$message.success("提交成功");
              this.getlist();
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    handleSizeChange(val) {
      console.log(val);
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pagination.page = val;
      this.getlist();
    },
    prev() {
      this.pagination.page = this.pagination.page - 1;
      this.getlist();
    },
    next() {
      console.log("ss");
      this.pagination.page = this.pagination.page + 1;
      this.getlist();
    },
    clolr_click() {
      getSalaryList({ color: this.color }).then((res) => {
        if (res.code == 200) {
          this.dataList = res.data.data;
          this.total = res.data.total;
        }
      });
    },
    clolr_clicks(){
      this.color =''
      getSalaryList(this.pagination).then((res) => {
        if (res.code == 200) {
          this.dataList = res.data.data;
          this.total = res.data.total;
        }
      });
    }

  },
};
</script>

<style></style>
